{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;height: 750px">


    <div class="layui-form" action="" method="post">
        <input type="hidden" value="{$info.id | default = ''}" id="id">
        <input type="hidden" value="{$info.city_id | default = ''}" id="city_id_1">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>省份名称</label>
            <div class="layui-input-inline">
            <select name="prov_id"   lay-filter="province_id">
                <option value="">筛选省份</option>
                {foreach $pro as $v}
                <option value="{$v.id}" {if(isset($info) && $info.prov_id == $v.id)}selected{/if}>{$v.province}</option>
                {/foreach}
            </select>
        </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>城市名称</label>
            <div class="layui-input-inline">
                <select name="city_id"   id="city_id">
                    <option value="">筛选城市</option>
                    {if(isset($info) && $info.city_id)}
                    <option value="{$info.city_id}" selected>{$info.city}</option>
                    {/if}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>区域名称</label>
            <div class="layui-input-inline">
                <input type="text" name="area"  lay-verify="title" value="{$info.area | default=''}" autocomplete="off" placeholder="请输入区域名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </div>
</div>
{include file='common/footer'}


<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });


        //    省市区联动
        form.on('select(province_id)', function(data){
            var value = data.value;
            var city_id = $('#city_id_1').val();
            $.ajax({
                type:'get',
                url:'/index/user/city?province_id='+value,
                dataType:'json',
                success:function (data) {
                    if(data.code == 200){
                        var html = '';
                        $.each(data.data,function (i,v) {
                            if(v.id == city_id ){
                                html+='<option value="'+v.id+'" selected>'+v.city+'</option>';
                            }else{
                                html+='<option value="'+v.id+'" >'+v.city+'</option>';
                            }

                        });
                        $('#city_id').html(html);
                        form.render('select');
                    }
                }
            });

        });



        //创建一个编辑器
        var editIndex = layedit.build('demo');

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });



        //监听提交
        form.on('submit(demo1)', function(data){
            var id = $('#id').val();
            data.field['id'] = id;
            $.ajax({
                url: '{:url("Basedata/areaAdd")}',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (obj) {
                    if(obj.code==200){
                        parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index,data.field); //再执行关闭
                    }
                    if(obj.code==400){
                        layer.msg(obj.msg, {icon: 5,time: 1000});
                    }
                },
                error:function(data){
                    console.log(data);
                }
            });

        });


    });
</script>

</body>
</html>